using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class SysFileUploadMap : EntityTypeConfiguration<SysFileUpload>
	{
		public SysFileUploadMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.Title)
				.IsRequired()
				.HasMaxLength(100);
				
			this.Property(t => t.NameValue)
				.IsRequired()
				.HasMaxLength(50);
				
			this.Property(t => t.FileType)
				.HasMaxLength(4);
				
			// Table & Column Mappings
			this.ToTable("SysFileUploads");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.PatientId).HasColumnName("PatientId");
			this.Property(t => t.FileCategoryId).HasColumnName("FileCategoryId");
			this.Property(t => t.SpecialistId).HasColumnName("SpecialistId");
			this.Property(t => t.Title).HasColumnName("Title");
			this.Property(t => t.NameValue).HasColumnName("NameValue");
			this.Property(t => t.Intro).HasColumnName("Intro");
			this.Property(t => t.FileSize).HasColumnName("FileSize");
			this.Property(t => t.FileType).HasColumnName("FileType");
			this.Property(t => t.StreamValue).HasColumnName("StreamValue");

			// Relationships
			this.HasOptional(t => t.Patient)
				.WithMany(t => t.SysFileUploads)
				.HasForeignKey(d => d.PatientId);
				
			this.HasRequired(t => t.SysFileCategory)
				.WithMany(t => t.SysFileUploads)
				.HasForeignKey(d => d.FileCategoryId);
				
		}
	}
}

